import sys
from PyQt5.QtWidgets import QMainWindow, QApplication, QTabBar, QWidget, QVBoxLayout, QMessageBox
from UI.LoginForm import Ui_LoginForm
from service.login_service import LoginService
from main import Main
class LoginController(QWidget,Ui_LoginForm):
    def __init__(self):
        super().__init__()
        self.setupUi(self)
        self.pushButton_login.clicked.connect(self.login)

    def login(self):
        if self.lineEdit_user.text() and self.lineEdit_pwd.text():
            login_service = LoginService(user=self.lineEdit_user.text(),pwd=self.lineEdit_pwd.text())
            if login_service.login():
                self.main_window = Main(login_user=self.lineEdit_user.text())
                self.main_window.show()
                self.close()


            else:
                QMessageBox.information(None,"信息","用户名，密码错误！！")

        else:
            QMessageBox.information(None,"信息","请输入用户名、密码！！")


if __name__ == '__main__':
    app = QApplication(sys.argv)
    login = LoginController()
    login.show()
    sys.exit(app.exec_())